package com.vogue.api.common.security.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.AuthenticatedPrincipal;
import org.springframework.security.core.GrantedAuthority;

import java.io.Serializable;
import java.util.Collection;

@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Oauth2User implements AuthenticatedPrincipal,Serializable {

    //用户ID
    private Long id;

    //昵称
    private String nickname;

    //手机号
    private String mobile;

    //头像
    private String avatar;

    //角色
    private Integer role;

    private Collection<? extends GrantedAuthority> authorities;

    public Oauth2User(String nickname, String mobile, String avatar) {
        this.nickname = nickname;
        this.mobile = mobile;
        this.avatar = avatar;
    }
    public Oauth2User(Long id,String nickname, String mobile, String avatar) {
        this.id = id;
        this.nickname = nickname;
        this.mobile = mobile;
        this.avatar = avatar;
    }
    public Oauth2User(Long id,String nickname, String mobile, String avatar,Integer role) {
        this.id = id;
        this.role = role;
        this.nickname = nickname;
        this.mobile = mobile;
        this.avatar = avatar;
    }

    @Override
    public String getName() {
        // 返回经过身份验证的名称（账号唯一标识），可以是用户ID，这里采用手机号
        return mobile;
    }
}
